package com.Cfeng.XiaohuanChat.domain;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author Cfeng
 * @date 2022/8/21
 * 验证码是作为一个info放在用户session中，可以直接放在Redis中，但是这里直接设置手动存储
 */

public class CaptchaCodeVo implements Serializable {

    private static final long serialVersionUID = -1088459535471769468L;
    //验证码
    private String code;

    //过期时间s
    private LocalDateTime expireTime;

    public CaptchaCodeVo(String code,int expireAfterSeconds) {
        this.code = code;
        //过期时间为创建之后60s
        this.expireTime = LocalDateTime.now().plusSeconds(expireAfterSeconds);
    }

    //是否过期,晚于过期时间旧过期
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    public String getCode() {
        return this.code;
    }
}
